Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support env files #1022

Merged
merged 20 commits into from
Dec 24, 2024
Merged

Conversation

easymikey
Copy link
Contributor

@easymikey easymikey commented Dec 23, 2024

Fixes #974

zx --env=/path/to/some.env my-script.mjs
  • Tests pass
  • Appropriate changes to README are included in PR

src/cli.ts Outdated Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
src/util.ts Outdated Show resolved Hide resolved
src/util.ts Outdated Show resolved Hide resolved
src/util.ts Outdated Show resolved Hide resolved
test/cli.test.js Outdated Show resolved Hide resolved
@easymikey easymikey requested a review from antongolub December 23, 2024 19:59
Copy link
Collaborator

@antongolub antongolub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done. Update plz 'man' and docs too.

src/util.ts Outdated Show resolved Hide resolved
src/util.ts Outdated Show resolved Hide resolved
.size-limit.json Outdated Show resolved Hide resolved
@easymikey
Copy link
Contributor Author

Almost done. Update plz 'man' and docs too.

Man updated. I'll update docs in the morning

src/util.ts Outdated Show resolved Hide resolved
@easymikey
Copy link
Contributor Author

Almost done. Update plz 'man' and docs too.

Docs updated

docs/cli.md Outdated Show resolved Hide resolved
src/util.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@antongolub antongolub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in most. Thanks!

@antongolub
Copy link
Collaborator

https://github.com/google/zx/actions/runs/12478218485

/usr/bin/bash: line 1: BAR: unbound variable
Error: /usr/bin/bash: line 1: BAR: unbound variable
    at Proxy.set (/home/runner/work/zx/zx/build/core.cjs:274:18)
    exit code: 1
    # Subtest: supports `--env` options with file
    not ok 12 - supports `--env` options with file
      ---
      duration_ms: 143.932467
      location: '/home/runner/work/zx/zx/test/cli.test.js:153:3'
      failureType: 'testCodeFailure'
      error: |-
        /usr/bin/bash: line 1: BAR: unbound variable
        Error: /usr/bin/bash: line 1: BAR: unbound variable
            at Proxy.set (/home/runner/work/zx/zx/build/core.cjs:274:18)
            exit code: 1
            at Proxy.set (/home/runner/work/zx/zx/build/core.cjs:274:18)
            exit code: 1
      code: 'ERR_TEST_FAILURE'

@easymikey
Copy link
Contributor Author

https://github.com/google/zx/actions/runs/12478218485

/usr/bin/bash: line 1: BAR: unbound variable
Error: /usr/bin/bash: line 1: BAR: unbound variable
    at Proxy.set (/home/runner/work/zx/zx/build/core.cjs:274:18)
    exit code: 1
    # Subtest: supports `--env` options with file
    not ok 12 - supports `--env` options with file
      ---
      duration_ms: 143.932467
      location: '/home/runner/work/zx/zx/test/cli.test.js:153:3'
      failureType: 'testCodeFailure'
      error: |-
        /usr/bin/bash: line 1: BAR: unbound variable
        Error: /usr/bin/bash: line 1: BAR: unbound variable
            at Proxy.set (/home/runner/work/zx/zx/build/core.cjs:274:18)
            exit code: 1
            at Proxy.set (/home/runner/work/zx/zx/build/core.cjs:274:18)
            exit code: 1
      code: 'ERR_TEST_FAILURE'

Yeap, I fixed.

@easymikey
Copy link
Contributor Author

Fix prettier

@easymikey easymikey requested a review from antongolub December 24, 2024 07:42
@easymikey easymikey force-pushed the support-env-files-for-cli branch from 44f81ad to db62520 Compare December 24, 2024 07:50
Copy link
Collaborator

@antongolub antongolub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@antongolub antongolub merged commit 36b42d8 into google:main Dec 24, 2024
19 checks passed
@mdevils
Copy link

mdevils commented Dec 24, 2024

Why a custom implementation and not dotenv?

@easymikey
Copy link
Contributor Author

Why a custom implementation and not dotenv?

I figured that would be enough weight for simple logic.

@mdevils
Copy link

mdevils commented Dec 24, 2024

@easymikey dotenv has none own dependencies, and the whole code is 360 lines of code.

It is simple today, tomorrow people will request variable expansion and what's your plan? Copy dotenv logic?

@easymikey
Copy link
Contributor Author

It is simple today, tomorrow people will request variable expansion and what's your plan? Copy dotenv logic?

I believe that if people demand it, then it can be done. Premature optimization is not needed here. But it's better for you to communicate with the mentainers.

@1e9y
Copy link
Contributor

1e9y commented Dec 24, 2024

Strictly speaking, passing custom env file is not required, as you can simple use dotenv explicitly in your script:

#!/usr/bin/env zx

import "dotenv/config";

await $`env`.pipe(process.stdout);

@easymikey
Copy link
Contributor Author

easymikey commented Dec 24, 2024

Strictly speaking, passing custom env file is not required, as you can simple use dotenv explicitly in your script:

#!/usr/bin/env zx

import "dotenv/config";

await $`env`.pipe(process.stdout);

Or this

#!/usr/bin/env zx

import "dotenv/config";

await $({
  preferLocal,
  env: process.env,
});


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: provide support for .env files injects via CLI
5 participants